using System;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using Entity;
using Utilities;


namespace DAL
{
	
    public class InGroupDataAccess : FreshCmsAccessBase
    {
        #region code CMS

        public List<InGroup> GetInGroupList()
        {
            try
            {
                const string spName = "spi_InGroup_GetList";

                var InGroupList = DbHelper.ExecuteSPList<InGroup>(spName);
                return InGroupList;
            }
            catch (Exception exp)
            {
                Logger.WriteLog(Logger.LogType.Error,
                                "File: " + (new StackTrace().GetFrame(0).GetMethod().DeclaringType.Name) +
                                " --- Function: " + (new StackTrace().GetFrame(0).GetMethod().Name) +
                                " --- Mess: " + exp.ToString());
                return new List<InGroup>();
            }
        }

        //public List<InGroup> GetInGroupListByPaging(int pageIndex, int pageSize, ref int totalRecord)
        //{
        //    try
        //    {
        //        const string spName = "spi_InGroup_GetByPaging";
        //        var sqlParams = new[]
        //                            {
        //                                new SqlParameter("@PageIndex", pageIndex),
        //                                new SqlParameter("@PageSize", pageSize),
        //                                new SqlParameter("@TotalRecord", totalRecord)
        //                            };

        //        SqlCommand sqlCommand = new SqlCommand(spName);
        //        sqlCommand.CommandType = CommandType.StoredProcedure;
        //        sqlCommand.CommandText = spName;
        //        sqlCommand.Parameters.AddRange(sqlParams);
        //        sqlCommand.Parameters["@TotalRecord"].Direction = ParameterDirection.Output;
        //        var InGroupList = DbHelper.ExecuteSqlList<InGroup>(sqlCommand);
        //        if (sqlCommand.Parameters["@TotalRecord"].Value != null)
        //        {
        //            totalRecord = (int) sqlCommand.Parameters["@TotalRecord"].Value;
        //        }

        //        return InGroupList;
        //    }
        //    catch (Exception exp)
        //    {
        //        //Logger.WriteLog(Logger.LogType.Error, exp.ToString());
        //        return new List<InGroup>();
        //    }
        //}

        //public InGroup GetInGroupById(int groupId)
        //{
        //    try
        //    {
        //        const string spName = "spi_InGroup_GetById";
        //        var sqlParams = new[]
        //                            {
        //                                new SqlParameter("@GroupId", groupId)
        //                            };

        //        var InGroup = DbHelper.ExecuteSPList<InGroup>(spName, sqlParams).SingleOrDefault();
        //        return InGroup;
        //    }
        //    catch (Exception exp)
        //    {
        //        //Logger.WriteLog(Logger.LogType.Error, exp.ToString());
        //        return null;
        //    }
        //}

        //public int InsertInGroup(InGroup InGroup)
        //{
        //    try
        //    {
        //        const string spName = "spi_InGroup_Insert";
        //        var sqlParams = new[]
        //                            {

        //                                new SqlParameter("@GroupName", InGroup.GroupName),
        //                                new SqlParameter("@GroupStatus", InGroup.GroupStatus),
        //                                new SqlParameter("@GroupId", InGroup.GroupId),

        //                            };

        //        SqlCommand sqlCommand = new SqlCommand(spName);
        //        sqlCommand.CommandType = CommandType.StoredProcedure;
        //        sqlCommand.CommandText = spName;
        //        sqlCommand.Parameters.AddRange(sqlParams);
        //        sqlCommand.Parameters["@GroupId"].Direction = ParameterDirection.Output;
        //        DbHelper.ExecuteNonQuery(sqlCommand);
        //        if (sqlCommand.Parameters["@GroupId"].Value != null)
        //        {
        //            return (int) sqlCommand.Parameters["@GroupId"].Value;
        //        }

        //        return 0;


        //    }
        //    catch (Exception exp)
        //    {
        //        Logger.WriteLog(Logger.LogType.Error, exp.ToString());

        //        return -1;
        //    }
        //}

        public int UpdateInGroup(InGroup InGroup)
        {
            try
            {
                const string spName = "spi_InGroup_Update";
                var sqlParams = new[]
                                    {
										new SqlParameter("@GroupId", InGroup.GroupId)
										, new SqlParameter("@GroupName", InGroup.GroupName)
										, new SqlParameter("@GroupStatus", InGroup.GroupStatus)
                                    };

                var returnVal = DbHelper.ExecuteInt32SP(spName, sqlParams);

                return returnVal;
            }
            catch (Exception exp)
            {
                Logger.WriteLog(Logger.LogType.Error,
                                "File: " + (new StackTrace().GetFrame(0).GetMethod().DeclaringType.Name) +
                                " --- Function: " + (new StackTrace().GetFrame(0).GetMethod().Name) +
                                " --- Mess: " + exp.ToString());
                return -1;
            }
        }

        public int DeleteInGroup(int groupId)
        {
            try
            {
                const string spName = "spi_InGroup_Delete";
                var sqlParams = new[]
                                {
                                    new SqlParameter("@GroupId", groupId)
                                };

                var returnVal = DbHelper.ExecuteInt32SP(spName, sqlParams);

                return returnVal;
            }
            catch (Exception exp)
            {
                Logger.WriteLog(Logger.LogType.Error,
                                "File: " + (new StackTrace().GetFrame(0).GetMethod().DeclaringType.Name) +
                                " --- Function: " + (new StackTrace().GetFrame(0).GetMethod().Name) +
                                " --- Mess: " + exp.ToString());
                return -1;
            }
        }
		#endregion
    }
}
